package com.business_clean.ui.adapter.custom;

import android.text.Editable;
import android.text.InputFilter;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;

import androidx.annotation.NonNull;

import com.business_clean.R;
import com.business_clean.app.base.BaseActivity;
import com.business_clean.app.uitl.DecimalDigitsInputFilter;
import com.business_clean.data.mode.custom.WorkPostData;
import com.business_clean.data.mode.job.JobListEntity;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

public class ProjectWorkAdapter extends BaseQuickAdapter<JobListEntity, BaseViewHolder> {
    public ProjectWorkAdapter() {
        super(R.layout.item_project_work);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, JobListEntity item) {
        baseViewHolder.setText(R.id.tv_item_project_work, item.getJob_name());
        //删除该项
        baseViewHolder.getView(R.id.iv_item_project_work).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getData().remove(getItemPosition(item));
                notifyDataSetChanged();
            }
        });

        //edit
        EditText editText = baseViewHolder.getView(R.id.et_item_project_work);
        editText.setText(item.getJob_human_num());
        editText.setFilters(new InputFilter[]{new DecimalDigitsInputFilter(2), new InputFilter.LengthFilter(8)});
        editText.addTextChangedListener(new MyTextChangedListener(item));
    }

    public class MyTextChangedListener implements TextWatcher {

        public JobListEntity contents;

        public MyTextChangedListener(JobListEntity contents) {
            this.contents = contents;
        }

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (contents != null && !TextUtils.isEmpty(editable)) {
                contents.setJob_human_num(editable.toString());
            }
        }
    }


    public boolean checkRepeatData(JobListEntity data) {
        for (JobListEntity jobList : getData()) {
            if (data.getUuid().equals(jobList.getUuid())) {
                return true;
            }
        }
        return false;
    }
}
